home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group96a.txt
/
000090_icon-group-sender _Mon Apr 15 13:44:56 1996.msg
< prev
next >
Wrap
Internet Message Format
|
1996-09-05
|
2KB
Received: by cheltenham.cs.arizona.edu; Mon, 15 Apr 1996 16:55:26 MST
Date: Mon, 15 Apr 1996 13:44:56 -0700
From: swampler@noao.edu
Subject: Re: Making a list out of a generated sequence
To: H.Lawson@tees.ac.uk
Cc: icon-group@cs.arizona.edu
Message-Id: <swampler-9603152044.AA00501630@orpheus.gemini.edu>
In-Reply-To: <317260B1.7F93@tees.ac.uk>
Errors-To: icon-group-errors@cs.arizona.edu
Status: O
Hamish Lawson wrote:
> Is there an easy way to make a list out of a generated sequence? I tried
> enclosing the generator sequence in square brackets, as below, but it
> doesn't appear to work.
>
> every write(sort([!"string"]))
>
> Am I obliged to write a loop that appends each item of the generated
> sequence to a list?:
>
> tempList := list()
> every tempList |||:= [!"string"]
> every write(!sort(tempList))
Yes, you must do something like this, though I'd use the put() function
instead of list concatenation; you're building lots of temporary lists
that aren't needed. If you're into conciseness, you can do it as:
every tempList := put([], !"string")
> If so, it would seem to me to be a curious lack of symmetry that the
> language provides the ! operator to generate elements of a list, but no
> corresponding convenient mechanism for collecting into a list a
> generated sequence of values.
Well, that's partly because of the nature of goal-directed evaluation.
It sounds as though you'd like an operator that incorporates the
functionality of the "every" expression. I find the expression
put([], expression)
sufficient for most such uses, and have only ever used it inside an
every expression. If you're fairly new to Icon, however, it might take
some time to work out why this works (but when you do, you'll
understand a little more about goal-directed evaluation!).
If you're not into conciseness, use:
TempList := list() # or TempList := []
every put(TempList, !"string)
instead.
--
Steve Wampler - swampler@gemini.edu [Gemini 8m Telescopes Project (under AURA)]
The Gods that smiled upon your birth are laughing now. -- fortune cookie